"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const global_1 = require("../../../config/global");
function registerEndNode(lf) {
    lf.register('endNode', ({ RectNode, RectNodeModel, h }) => {
        class Node extends RectNode {
            getTitleElement() {
                const { model } = this.props;
                const { x, y } = model;
                const style = model.getNodeStyle();
                const properties = model.getProperties();
                // 创建一个文本输入框
                return h("g", {}, [
                    h('text', {
                        fill: '#000000',
                        fontSize: 16,
                        x: x - 60,
                        y: y - 30,
                        width: 50,
                        height: 25
                    }, 'CC_EndNode')
                ]);
            }
            ;
            getAllChoiceList() {
                const { model } = this.props;
                const { width, height, x, y, } = model;
                const style = model.getNodeStyle();
                const nodeData = model.getData();
                const properties = model.getProperties();
                return h("g", {}, h("foreignObject", Object.assign(Object.assign({}, style), { id: "choice", type: "choice", height: 26, width: 208, y: y, x: x - 102 }), [
                    h("textarea", {
                        style: {
                            width: "95%",
                            height: "70%",
                            resize: "none" // 禁止调整文本框大小
                        },
                        value: properties.endContent || '',
                        onInput: (event) => {
                            let newContent = event.target.value;
                            properties.endContent = newContent;
                            model.setProperties(properties);
                        },
                    })
                ]));
            }
            getShape() {
                const { model } = this.props;
                const { width, height, x, y, } = model;
                const style = model.getNodeStyle();
                const properties = model.getProperties();
                return h("g", {}, [
                    h("rect", Object.assign(Object.assign({}, style), { id: "svg_1", height: 70, width: 220, x: x - 220 / 2, y: y - 20, fill: "#1ed4fd" })),
                    h("rect", Object.assign(Object.assign({}, style), { id: "svg_7", height: 30, width: 220, x: x - 220 / 2, y: y - 30 - 20 })),
                    this.getTitleElement(),
                    this.getAllChoiceList(),
                ]);
            }
        }
        class Model extends RectNodeModel {
            constructor(data, graphModel) {
                data.text = {
                    value: (data.text && data.text.value) || '未命名节点-结束',
                    x: data.x,
                    y: data.y + 70
                };
                super(data, graphModel);
                this.radius = 20;
            }
            initNodeData(data) {
                if (!data.virtual) {
                    const end = new global_1.EndNode();
                    data.properties = Object.assign({}, end);
                    this.width = 220;
                    this.height = 100;
                }
                super.initNodeData(data);
                const onlyPosAsConnect = {
                    message: "连接对应的锚点",
                    validate: (sourceNode, targetNode, sourceAnchor, targetAnchor) => {
                        return sourceAnchor.type === 'right' && targetAnchor.type === 'left';
                    },
                };
                this.sourceRules.push(onlyPosAsConnect);
            }
            addField() {
                // 更新节点连接边的path
                this.incoming.edges.forEach((egde) => {
                    // 调用自定义的更新方案
                    egde.updatePathByAnchor();
                });
                this.outgoing.edges.forEach((edge) => {
                    // 调用自定义的更新方案
                    edge.updatePathByAnchor();
                });
            }
            getAnchorStyle(anchorInfo) {
                const style = super.getAnchorStyle(anchorInfo);
                if (anchorInfo.type === "left") {
                    style.fill = "red";
                    style.hover.fill = "transparent";
                    style.hover.stroke = "transpanrent";
                    style.className = "lf-hide-default";
                }
                else {
                    style.fill = "green";
                }
                return style;
            }
            setIsShowAnchor() {
                this.isShowAnchor = true;
            }
            getDefaultAnchor() {
                const { width, height, x, y, id } = this;
                return [{
                        x: x + 18 - width / 2,
                        y: y + 16 - height / 2,
                        type: "left",
                        edgeAddable: false,
                        id: `${id}_0`,
                    }];
            }
        }
        return {
            view: Node,
            model: Model
        };
    });
}
exports.default = registerEndNode;
